using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Entities;
/// <summary>
/// Summary description for GiayPhepLaiXeDAL
/// </summary>
namespace DataAccess 
{
    
    public class GiayPhepLaiXeDAL  : BaseDAL
    {
    	#region Private Variables

		#endregion
		
 #region Public Constructors
        public GiayPhepLaiXeDAL()
        {
            //
            // TODO: Add constructor logic here
            //
            
        }
 #endregion       

	
		
#region Public Methods
        public int Insert(GiayPhepLaiXe objGiayPhepLaiXe)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@DoiTuonGhiDanh", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.DoiTuonGhiDanh;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@SoGiayPhepLaiXe", SqlDbType.NVarChar);
Sqlparam.Value = objGiayPhepLaiXe.SoGiayPhepLaiXe;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.HangXe;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NoiCap", SqlDbType.NVarChar);
Sqlparam.Value = objGiayPhepLaiXe.NoiCap;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NgayCap", SqlDbType.DateTime);
Sqlparam.Value = objGiayPhepLaiXe.NgayCap;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(GiayPhepLaiXe objGiayPhepLaiXe)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@DoiTuonGhiDanh", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.DoiTuonGhiDanh;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@SoGiayPhepLaiXe", SqlDbType.NVarChar);
Sqlparam.Value = objGiayPhepLaiXe.SoGiayPhepLaiXe;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.HangXe;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NoiCap", SqlDbType.NVarChar);
Sqlparam.Value = objGiayPhepLaiXe.NoiCap;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@NgayCap", SqlDbType.DateTime);
Sqlparam.Value = objGiayPhepLaiXe.NgayCap;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(GiayPhepLaiXe objGiayPhepLaiXe)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public GiayPhepLaiXe Select(GiayPhepLaiXe objGiayPhepLaiXe)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
Sqlparam.Value = objGiayPhepLaiXe.Khoa;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["Khoa"]))
objGiayPhepLaiXe.Khoa=Convert.ToInt64(dr["Khoa"]);
if(!Convert.IsDBNull(dr["DoiTuonGhiDanh"]))
objGiayPhepLaiXe.DoiTuonGhiDanh=Convert.ToInt64(dr["DoiTuonGhiDanh"]);
if(!Convert.IsDBNull(dr["SoGiayPhepLaiXe"]))
objGiayPhepLaiXe.SoGiayPhepLaiXe=Convert.ToString(dr["SoGiayPhepLaiXe"]);
if(!Convert.IsDBNull(dr["HangXe"]))
objGiayPhepLaiXe.HangXe=Convert.ToInt64(dr["HangXe"]);
if(!Convert.IsDBNull(dr["NoiCap"]))
objGiayPhepLaiXe.NoiCap=Convert.ToString(dr["NoiCap"]);
if(!Convert.IsDBNull(dr["NgayCap"]))
objGiayPhepLaiXe.NgayCap=Convert.ToDateTime(dr["NgayCap"]);

            }
             return objGiayPhepLaiXe;
        }

        public ArrayList SelectAllToArray( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrGiayPhepLaiXe = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
GiayPhepLaiXe objGiayPhepLaiXe= new GiayPhepLaiXe();
if(!Convert.IsDBNull(dr["Khoa"]))
objGiayPhepLaiXe.Khoa=Convert.ToInt64(dr["Khoa"]);
if(!Convert.IsDBNull(dr["DoiTuonGhiDanh"]))
objGiayPhepLaiXe.DoiTuonGhiDanh=Convert.ToInt64(dr["DoiTuonGhiDanh"]);
if(!Convert.IsDBNull(dr["SoGiayPhepLaiXe"]))
objGiayPhepLaiXe.SoGiayPhepLaiXe=Convert.ToString(dr["SoGiayPhepLaiXe"]);
if(!Convert.IsDBNull(dr["HangXe"]))
objGiayPhepLaiXe.HangXe=Convert.ToInt64(dr["HangXe"]);
if(!Convert.IsDBNull(dr["NoiCap"]))
objGiayPhepLaiXe.NoiCap=Convert.ToString(dr["NoiCap"]);
if(!Convert.IsDBNull(dr["NgayCap"]))
objGiayPhepLaiXe.NgayCap=Convert.ToDateTime(dr["NgayCap"]);
arrGiayPhepLaiXe.Add(objGiayPhepLaiXe);
}
            }
               return arrGiayPhepLaiXe;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "GiayPhepLaiXe_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
#endregion          
    
    }

}
